package com.neurotech.pcc.other

import android.app.Activity
import android.os.Build
import android.support.v4.app.Fragment
import android.view.Gravity
import android.view.View
import android.widget.Toast
import androidx.navigation.fragment.NavHostFragment

/**
 * Created by shenhua on 2018/10/10.
 * @author shenhua
 *         Email shenhuanet@126.com
 */
fun Activity.toast(msg: String) {
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}

fun Fragment.toast(msg: String) {
    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
}

fun Fragment.toastCenter(msg: String) {
    val toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT)
    toast.setGravity(Gravity.CENTER, 0, 0)
    toast.show()
}

fun Fragment.pop() {
    NavHostFragment.findNavController(this).navigateUp()
}

fun darkStatusBarIcon(decorView: View?) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
    }
}

fun liteStatusBarIcon(decorView: View?) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    }
}